<?php
if(!defined('IN_IBEIKE')) {
	exit('Access Denied');
}
class common_convert{
	private $inData;
	private $tmpData;
	private $type;
	private $encode='utf-8';
	public function __construct($arr){
		if(is_array($arr)||$arr){
			$this->inData=$arr;
		}else{
			return 1;
		}
	}
	public function convert_xml(){
	}
	public function convert_json(){
		try{
		$this->tmpData=json_encode($this->inData);
		}catch (Exception $e){
			$e->getCode();
		}
		$this->type='json';
		return '0';
	}
	public function convert_array(){
		$this->tmpData=print_r($this->inData,true);
		return '0';
	}
	public function output(){
		if($this->type){
			if($this->tmpData){
				return $this->tmpData;
			}else{
				return 'data error';
			}
		}else{
			return 'type error';
		}
	}
	public function output_file($filename){
		if($filename){
			if($file=fopen(DIR_ROOT.'./data/sysdata/'.$filename,'w+')){
				if(fwrite($file,$this->tmpData)){
					fflush($file);
					fclose($file);
					return '0';
				}else{
					return '1';
				}
			}else{
				return '2';
			}
		}else{
			return '3';
		}
	}
}
?>